{extend name="public:base" /}
{block name="css"}

{/block}
{block name="theme"}权限管理{/block}
{block name="small_theme"}角色列表{/block}
{block name="content"}
<div class="col-xs-12 table-responsive">
    <div class="box box-list">
        <form class="ajaxForm2" method="post" action="{:url('role_group_runaccess')}">
            <table border="0" align="center" cellpadding="0" cellspacing="0" class="table table-striped table-hover table-condensed">
                <tr>
                    <td height="30" style="border-bottom:#CCCCCC solid 1px; line-height:25px;">配置规则:<br />
                        1、由于页面原因，权限分配为三级，同时控制左侧导航以及用户权限<br />
                        2、部分不需要分配的权限需要在Menu的控制器里手动添加<br />
                    </td>
                </tr>
                <tr>
                    <td height="30" style="padding-left:10px;border-bottom:#CCCCCC solid 1px; line-height:25px; background-color:#F4F8FB" class="icheck">
                        <label >
                            <input type="checkbox" id='chkAll' onclick='CheckAll(this.form)' value="全选" class="ace ace-checkbox-3"/>
                            <span class="lbl"> 权限全选</span>
                        </label>
                    </td>
                </tr>
                {foreach name="datab" item="vo"}
                    <tr>
                        <td height="40" style="border-bottom:#CCCCCC solid 1px;padding-left:10px;">
                            <label>
                                <input {in name="vo.id" value="$admin_group['rules']"}checked{/in} name="new_rules[]" class="ace ace-checkbox-4 checkbox-parent" type="checkbox"  value="{$vo.id}" dataid="id-{$vo['id']}" /><span class="lbl"> <strong>{$vo.title}</strong></span>
                            </label>
                        </td>
                    </tr>
                    {foreach name="vo['sub']" item="sub"}
                        <tr>
                            <td height="30" style="padding-left:30px;border-bottom:#E7EBF8 dashed 1px; color:#333333">
                                <label>
                                    <input {in name="sub.id" value="$admin_group['rules']"}checked{/in} name="new_rules[]" id="{$sub.id}" class="ace ace-checkbox-2 checkbox-parent checkbox-child" type="checkbox"  value="{$sub.id}" dataid="id-{$vo['id']}-{$sub['id']}" /><span class="lbl"> {$sub.title}</span>
                                </label>
                            </td>
                        </tr>
                        {if condition="!empty($sub['sub'])"}
                            <tr>
                                <td  height="30" style="padding-left:50px;border-bottom:#E7EBF8 dashed 1px; color:#333333">
                                    {foreach name="sub['sub']" item="subb"}
                                        <label class="thopen">
                                            <input {in name="subb.id" value="$admin_group['rules']"}checked{/in} name="new_rules[]" class="ace ace-checkbox-1 checkbox-parent checkbox-child" type="checkbox"  id="{$subb.id}" value="{$subb.id}" dataid="id-{$vo['id']}-{$sub['id']}-{$subb['id']}" />
                                            <span class="lbl" style="margin-right:20px;"> {$subb.title}</span>
                                        </label>
                                    {/foreach}
                                </td>
                            </tr>
                        {/if}
                    {/foreach}
                {/foreach}
            </table>
            <!--</div>-->
            <div class="btn-box" style="text-align: center">
                <input type="hidden" value="{$admin_group.id}" name="id">
                <button type="submit" class="btn btn-info" id="submit">确定</button>
                &nbsp; &nbsp; &nbsp;
                <button type="reset" class="btn btn-color-b">返回</button>
            </div>
        </form>
    </div>
    <!-- /.box -->
</div>
{/block}
{block name="js"}
<script src="__STATIC__/admin/js/ajaxForm.js"></script>
<script>
    /* 权限配置 */
    $(function () {
        //动态选择框，上下级选中状态变化
        $('input.checkbox-parent').on('change', function () {
            var dataid = $(this).attr("dataid");
            $('input[dataid^=' + dataid + '-]').prop('checked', $(this).is(':checked'));
        });
        $('input.checkbox-child').on('change', function () {
            var dataid = $(this).attr("dataid");
            dataid = dataid.substring(0, dataid.lastIndexOf("-"));
            var parent = $('input[dataid=' + dataid + ']');
            if ($(this).is(':checked')) {
                parent.prop('checked', true);
                //循环到顶级
                while (dataid.lastIndexOf("-") != 2) {
                    dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                    parent = $('input[dataid=' + dataid + ']');
                    parent.prop('checked', true);
                }
            } else {
                //父级
                if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                    parent.prop('checked', false);
                    //循环到顶级
                    while (dataid.lastIndexOf("-") != 2) {
                        dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                        parent = $('input[dataid=' + dataid + ']');
                        if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                            parent.prop('checked', false);
                        }
                    }
                }
            }
        });
    });

    /**
     * 全选方法
     * @param form
     * @constructor
     */
    function CheckAll(form) {
        for (var i = 0; i < form.elements.length; i++) {
            var e = form.elements[i];
            if (e.Name != 'chkAll' && e.disabled == false) {
                e.checked = form.chkAll.checked;
            }
        }
    }
    /* 通用表单不带检查操作，失败跳转 */
    $(function () {
        $('.ajaxForm2').ajaxForm({
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });
    });
    highlight_subnav("{:url('index')}");
</script>

{/block}